package aryn.framework.display;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.List;

import aryn.framework.graphic.Load;

public class MyFrame extends Frame {
	private static final long serialVersionUID = 1L;
	
	private List<MyCanvas> canvases = new ArrayList<MyCanvas>();
	
	public MyFrame(final int frameDimX, final int frameDimY) {	
		this.setLayout(null);
		this.setSize(frameDimX + 16,frameDimY + 38);
		this.setLocationRelativeTo(null);
		this.setIgnoreRepaint(true);
		this.setVisible(true);
		this.requestFocus();
		
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				for(MyCanvas canvas : canvases)
					canvas.stop();
				MyFrame.this.setVisible(false);
				MyFrame.this.dispose();
				System.exit(0);
			}
		});
	}
	
	public MyFrame(String imagePath) {
		this();
		MyCanvas canvas = new MyCanvas();
		canvas.addImage(imagePath, 0, 0);
		this.addCanvas(canvas);
	}
	
	public MyFrame() {
		this(800, 600);
	}

	public List<MyCanvas> getCanvases() {
		return canvases;
	}
	
	public void addCanvas(MyCanvas canvas) {
		canvases.add(canvas);
		this.add(canvas);
		(canvases.get(canvases.size()-1)).startGraphicThread();
		this.validate();
	}
	
	  // ******************* \\
	 //	   PUBLIC METHODS	  \\
	// *********************** \\
	

	public void setIconImage(String iconPath) {
        this.setIconImage(Load.bufferedImage(iconPath));
	}

	
	  // ******************* \\
	 //		  GETTERS		  \\
	// *********************** \\
	
	
	
}
